<template>
    <transition name="el-zoom-in-top">
        <div v-show="isHome" class="transition-box">

            <div class="LevelBar-container" v-if="isHome">
                <span class="icon-home el-icon-mars-home2"></span>

                <!--面包屑导航条-->
                <el-breadcrumb separator="/" class="levelBar-wrapper">

                    <el-breadcrumb-item v-for="(item, index) in levelList" :key="item.path">

                        <span v-if='item.redirect === "noredirect" || index == levelList.length-1'>
                            {{item.name}}
                        </span>

                        <router-link v-else :to="item.redirect || item.path">
                            {{item.name}}
                        </router-link>

                    </el-breadcrumb-item>
                </el-breadcrumb>
            </div>

        </div>
    </transition>
</template>

<script>
    export default {
        name: 'LevelBar',
        data() {
            return {
                levelList: null,
                isHome: (this.$route.path !== '/dashboard')
            }
        },
        created() {
            this.getBreadcrumb()
        },
        methods: {
            getBreadcrumb() {
                let matched = this.$route.matched.filter(item => item.name)
                let first = matched[0]

                if (first && (first.name !== '主页' || first.path !== '')) {
                    matched = [{name: '主页', path: '/'}, ...matched]
                }
                this.levelList = matched
            }
        },
        watch: {
            $route() {
                this.getBreadcrumb()
                this.isHome = (this.$route.path !== '/dashboard')
            }
        }
    }
</script>

<!-- 局部样式 -->
<style rel="stylesheet/scss" lang="scss" scoped>
    .LevelBar-container {
        width: 100%;
        height: 30px;
        margin-bottom: 5px;
        .icon-home {
            color: #262e41;
            height: 30px;
            float: left;
            line-height: 30px;
            text-align: center;
            font-size: 20px;
            padding: 0 5px 0 5px;
        }
        .levelBar-wrapper.el-breadcrumb {
            float: left;
            box-sizing: border-box;
            height: 30px;
            line-height: 30px;
        }
    }
</style>